package com.loe.ui.quickjs

import androidx.annotation.Keep
import com.quickjs.JSContext
import com.quickjs.JSObject
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

lateinit var jsColor: JSColor

@Keep
class JSColor(context: JSContext) : JSObject(context)
{
    init
    {
        set("main", "#FD4A19")

        set("black", "#000000")
        set("text", "#303134")
        set("textLight", "#606266")
        set("gray", "#989a9e")
        set("hint", "#b8b8bf")
        set("line", "#dbdce0")
        set("bgDeep", "#f0f1f5")
        set("bg", "#f5f6fa")
        set("bgLight", "#f9fafc")
        set("white", "#ffffff")
        set("alpha", "#00000000")

        set("red", "#f63c54")
        set("orange", "#ffc44c")
        set("yellow", "#f2e033")
        set("green", "#55d13a")
        set("cyan", "#22d0a3")
        set("blue", "#46B4EB")
        set("purple", "#b54fe6")
        set("pink", "#f69ed3")
    }

    var main by color()

    var black by color()
    var text by color()
    var textLight by color()
    var gray by color()
    var hint by color()
    var line by color()
    var bgDeep by color()
    var bg by color()
    var bgLight by color()
    var white by color()
    var alpha by color()

    var red by color()
    var orange by color()
    var yellow by color()
    var green by color()
    var cyan by color()
    var blue by color()
    var purple by color()
    var pink by color()

    private fun color() = object : ReadWriteProperty<Any?, String>
    {
        override fun getValue(thisRef: Any?, property: KProperty<*>): String
        {
            return getString(property.name)
        }

        override fun setValue(thisRef: Any?, property: KProperty<*>, value: String)
        {
            set(property.name, value)
        }
    }
}
